/******************************************************************************
	This file is a part of the Snapshot Bioinformatics Project

	Copyright (C) 2012-2013 Jarom Schow

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

#include "SeqRange.h"

#include <QtCore/QStringList>

#include "SeqLocation.h"

using namespace Bio;

/**
**/
SeqRange::SeqRange()
{
}

/**
**/
SeqRange::SeqRange( const SeqRange &range ) : m_locations( range.m_locations )
{
}

/**
**/
SeqRange::~SeqRange()
{
}

/**
**/
void SeqRange::switchStrand()
{
	QMutableListIterator<SeqLocation>	locIt( m_locations );

	while( locIt.hasNext() )
		locIt.next().switchStrand();
}

/**
**/
void SeqRange::addLocation( const SeqLocation &location )
{
	m_locations.append( location );
}

/**
**/
bool SeqRange::isEmpty() const
{
	return m_locations.isEmpty();
}

/**
**/
int SeqRange::getNumLocations() const
{
	return m_locations.count();
}

/**
**/
QString SeqRange::toString() const
{
	if( m_locations.isEmpty() )
		return "Empty";

	if( m_locations.count() == 1 )
		return m_locations[0].toString();

	QListIterator<SeqLocation>	locIt( m_locations );
	QStringList					locations;

	while( locIt.hasNext() )
		locations.append( locIt.next().toString() );

	return QString( "[ %1 ]" ).arg( locations.join( ", " ) );
}

/**
**/
SeqLocation SeqRange::getLocation( int which ) const
{
	if( which < 0 || which >= m_locations.count() )
		return SeqLocation();

	return m_locations[which];
}

/**
**/
QListIterator<SeqLocation> SeqRange::getLocationIterator() const
{
	return QListIterator<SeqLocation>( m_locations );
}

/**
**/
SeqRange& SeqRange::operator=( const SeqRange &other )
{
	m_locations = other.m_locations;

	return *this;
}
